﻿using System;
using System.Collections.Generic;
using System.Text;
using Elota.SCAQGL.DAL;
using Elota.SCAQGL.Models;

namespace Elota.SCAQGL.BLL
{
    public class IllustrateBLL
    {
        private static IllustrateBLL instance = null;
        private static object obj = new object();
        /// <summary>
        /// 创建救援目标 BLL 单例
        /// </summary>
        public static IllustrateBLL Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (obj)
                    {
                        if (instance == null)
                            instance = new IllustrateBLL();
                    }
                }
                return instance;
            }
        }
        /// <summary>
        /// 获取所有应急预案信息
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public IList<Illustrate> GetModels(string strWhere)
        {
            return IllustrateDAL.Instance.GetModels(strWhere);
        }
        /// <summary>
        /// 更具主键获取应急预案信息 
        /// </summary>
        /// <param name="iKey"></param>
        /// <returns></returns>
        public Illustrate GetModelByKey(string iKey)
        {
            string strWhere = string.Format(" Where RescueTargetId ={0}", iKey);
            IList<Illustrate> models = IllustrateDAL.Instance.GetModels(strWhere);
            if (models.Count.Equals(0))
                return null;
            return models[0];
        }
        /// <summary>
        /// 保存对象
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Save(Illustrate model)
        {
            bool result = false;
            if (model.RescueTargetId.Equals(0))
                result = IllustrateDAL.Instance.Insert(model);
            else
                result = IllustrateDAL.Instance.Update(model);
            return result;
        }
        public bool Del(Illustrate model)
        {
           bool result = false;
           result = IllustrateDAL.Instance.Delete(model);
           return result;
        }
    }
}
